home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4485 < prev    next >
Encoding:
Text File  |  1996-08-05  |  940 b   |  28 lines

  1. Path: cymbal.aix.calpoly.edu!not-for-mail
  2. From: dstubbs@cymbal.aix.calpoly.edu (Dan Stubbs)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: random number
  5. Date: 4 Feb 1996 19:00:24 -0800
  6. Organization: California Polytechnic State University, San Luis Obispo
  7. Message-ID: <4f3rs8$2lvp@cymbal.aix.calpoly.edu>
  8. References: <1996Feb4.020051.12889@dcs.warwick.ac.uk>
  9. NNTP-Posting-User: dstubbs@cymbal.aix.calpoly.edu
  10.  
  11. In article <1996Feb4.020051.12889@dcs.warwick.ac.uk>,
  12. Daniel Castillo Molero <D.C.Molero@dcs.warwick.ac.uk> wrote:
  13. >Hi,
  14. >Could anybody help me to generate some code to produce
  15. >a random number between -3 and 3 ?
  16. >I'm trying to useárand(), but since it doesn't receive
  17.  
  18. Each time you call rand map the result into the interval -3 ... 3.
  19. You can do this, for example, as follows:
  20.  
  21.    r = (rand() % 7) - 3;
  22.  
  23. If you are using rand be sure and read about the role of srand
  24. in "initializing" the sequence of random numbers that are generated.
  25.  
  26.  
  27.  
  28.